package com.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.model.Card;

public class CardDAO {
	
	public static final String url = "jdbc:mysql://127.0.0.1/yujiaguan?useUnicode=true&characterEncoding=UTF-8";  
    public static final String name = "com.mysql.jdbc.Driver";  
    public static final String user = "root";  
    public static final String password = "123456";
    public static Connection conn = null;  
	
	public CardDAO() {
		
		try {  
            Class.forName(name); 
            if (conn == null) {
            	conn = DriverManager.getConnection(url, user, password); 
            }
        } catch (Exception e) {  
            e.printStackTrace();  
        } 
		
	}
	
	public void  createCard(Card card, int type) {
		
		
	
		String sql =null;



		if (type == 1) {
			sql = "insert into card(TYPE,MESSAGE,MEMBER_ID, NAME) values('"+
					"0"+"','"+"none"+"','"+card.getMemberID()+"','"+card.getName()+"');";
		} else {
			sql = "insert into card(TYPE,MESSAGE,MEMBER_ID, NAME) values('"+
				"1"+"','"+card.getMessage()+"','"+card.getMemberID()+"','"+card.getName()+"');";
		}
		
		PreparedStatement pst;
		try {
			pst = conn.prepareStatement(sql);
			pst.execute(sql);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
